#include "MyDeviceModel.h"

MyDeviceModel::MyDeviceModel(QList<DeviceInformation*> *devList, QObject *parent) : QAbstractTableModel(parent)
{
	deviceList = devList;
}

int MyDeviceModel::rowCount(const QModelIndex & ) const
{
	return deviceList->count();
}

int MyDeviceModel::columnCount(const QModelIndex & ) const
{
	return(4);
}

QVariant MyDeviceModel::data(const QModelIndex &index, int role) const
{
	if (!index.isValid())
		return QVariant();

	if (role == Qt::TextAlignmentRole)
	{
		return int(Qt::AlignLeft | Qt::AlignVCenter);
	}

	if (role == Qt::DisplayRole)
	{
		switch (index.column())
		{
		case 0: {return QString::fromStdWString( deviceList->at(index.row())->GetDeviceType() ); }
		case 1: {return QString::fromStdString( deviceList->at(index.row())->GetVendorName() ); }
		case 2: {return QString::fromStdString( deviceList->at(index.row())->GetDevName() ); }
		case 3: {return QString::fromStdString( deviceList->at(index.row())->isListened() );}
		}
	}

	return QVariant();
}

QVariant MyDeviceModel::headerData(int section, Qt::Orientation  orientation ,int role) const
{
	if (role != Qt::DisplayRole)
		return QVariant();
	QStringList headers;
	headers << "Device type" << "Vendor ID" << "Device ID" << "Is observed";
	if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
	{
		return headers[section];
	}
	return QVariant();
}

void MyDeviceModel::Update()
{
	reset();
}

